package com.lianniu.web.tea.user.eva.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.comment.controller.TeaRestUserCommentController;
import com.lianniu.web.tea.user.comment.model.TeaComment;
import com.lianniu.web.tea.user.eva.model.TeaEva;
import com.lianniu.web.tea.user.eva.service.ITeaUserEvaService;
import com.lianniu.web.util.DateUtil;
import com.lianniu.web.util.UUIDUtil;

@Controller
@RequestMapping("/rest/eva")
public class TeaRestUserEvaController {
	
	private final static Logger logger = Logger.getLogger(TeaRestUserEvaController.class);

	@Autowired
	private ITeaUserEvaService teaUserEvaService;
	
	@RequestMapping(value="/saveEva",method = RequestMethod.POST )
	public @ResponseBody BaseResult saveEva(HttpServletRequest req){
		logger.info("TeaRestUserEvaController  saveEva begin.");
		try {
			logger.info("saveEva begin.");
			String id = UUIDUtil.getUUID();
			String evaUserId = req.getParameter("evaUserId");
			String replyUserId = req.getParameter("replyUserId");
			String msg = req.getParameter("msg");
			String commentId = req.getParameter("commentId");
			String evaType = req.getParameter("evaType");
			TeaEva teaEva = new TeaEva();
			teaEva.setId(id);
			teaEva.setEvauserid(Integer.valueOf(evaUserId));
			if(!"".equals(replyUserId)){
				teaEva.setReplyuserid(Integer.valueOf(replyUserId));
			}
			teaEva.setMsg(msg);
			teaEva.setAddtime(DateUtil.getNowTime());
			teaEva.setCommentid(commentId);
			teaEva.setEvatype(evaType);
			

			BaseResult baseResult = teaUserEvaService.saveEva(teaEva);
			logger.info("saveEva end.");
			logger.info("TeaRestUserEvaController saveEva end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaRestUserEvaController saveEva error:" + e.getMessage());
			logger.error("TeaRestUserEvaController saveEva end.");
			return BaseResult.exception(e.getMessage());
		}
	}
}
